package com.example.time;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class time {
    public static void main(String[] args) {

        String a="2021-12-12 9:03:23";
        SimpleDateFormat f = new SimpleDateFormat("yyyy-mm-DD HH:mm:ss");
        try {
            Date nows =  f.parse(a);
            System.out.println(nows);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date now = null;
        try {
            now = f.parse(a);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        DateFormat d1 = DateFormat.getDateInstance(); //默认语言（汉语）下的默认风格（MEDIUM风格，比如：2008-6-16 20:54:53）
        String str1 = d1.format(now);
        DateFormat d3 = DateFormat.getDateTimeInstance();
        String str2 = d3.format(now);
        XMLGregorianCalendar gcc = null;
        XMLGregorianCalendar gcc2 = null;
        try {
            gcc = DatatypeFactory.newInstance().newXMLGregorianCalendar(str1);
            gcc2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(str2);
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
        }
        System.out.println(gcc);
        System.out.println(gcc2);
    }
}
